def add_to_arr_extra_param(arr, v):
  arr.append(v)

def transform0(df):
  import pandas as pd
  vocab = {}
  # 这是one-hot编码么
  for index, row in df.iterrows():
    for column_name, value in row.iteritems():
      print(column_name + "_" + str(value))
      vocab.setdefault(column_name + "_" + str(value), len(vocab))
  print(vocab)

  new_df = pd.DataFrame(columns=range(len(vocab)))
  for index, row in df.iterrows():
    new_df.loc[index] = 0.0
    for column_name, value in row.iteritems():
      index_in_vocab = vocab[column_name + "_" + str(value)]
      new_df.loc[index, index_in_vocab] = 1.0
  return new_df

# 这个方法写呲了, 每次都fit肯定不行啊
def transform(df):
  import pandas as pd
  def fit(df_to_fit):
    vocab = {}
    # 这是one-hot编码么
    for index, row in df_to_fit.iterrows():
      for column_name, value in row.iteritems():
        print(column_name + "_" + str(value))
        vocab.setdefault(column_name + "_" + str(value), len(vocab))
    print(vocab)

    def trans(df_to_trans):
      new_df = pd.DataFrame(columns=range(len(vocab)))
      for index, row in df_to_trans.iterrows():
        new_df.loc[index] = 0.0
        for column_name, value in row.iteritems():
          index_in_vocab = vocab[column_name + "_" + str(value)]
          new_df.loc[index, index_in_vocab] = 1.0
      return new_df
    return trans
  
  return fit(df)(df)

# AttributeError: Can't pickle local object 'transformer_1.<locals>.fit.<locals>.trans'
def transformer_1(df):
  import pandas as pd
  def fit(df_to_fit):
    vocab = {}
    for index, row in df.iterrows():
      for column_name, value in row.iteritems():
        print(column_name + "_" + str(value))
        vocab.setdefault(column_name + "_" + str(value), len(vocab))
    print(vocab)

    def trans(df_to_trans):
      new_df = pd.DataFrame(columns=range(len(vocab)))
      for index, row in df.iterrows():
        new_df.loc[index] = 0.0
        for column_name, value in row.iteritems():
          index_in_vocab = vocab[column_name + "_" + str(value)]
          new_df.loc[index, index_in_vocab] = 1.0
      return new_df
    return trans
  
  return fit(df)

# global是能dump了, load不了
def transformer_2(df):
  import pandas as pd
  global fit
  def fit(df_to_fit):
    vocab = {}
    for index, row in df.iterrows():
      for column_name, value in row.iteritems():
        print(column_name + "_" + str(value))
        vocab.setdefault(column_name + "_" + str(value), len(vocab))
    print(vocab)
    global trans
    def trans(df_to_trans):
      new_df = pd.DataFrame(columns=range(len(vocab)))
      for index, row in df.iterrows():
        new_df.loc[index] = 0.0
        for column_name, value in row.iteritems():
          index_in_vocab = vocab[column_name + "_" + str(value)]
          new_df.loc[index, index_in_vocab] = 1.0
      return new_df
    return trans
  
  return fit(df)